	-- 清理数据库日志文件
  ALTER DATABASE 要清理的数据库名称 SET RECOVERY SIMPLE WITH NO_WAIT
  GO
  ALTER DATABASE 要清理的数据库名称 SET RECOVERY SIMPLE   --简单模式
  GO
  USE 要清理的数据库名称
  GO
  DBCC SHRINKFILE (N'要清理的数据库名称_log' , 2, TRUNCATEONLY)  --设置压缩后的日志大小为2M，可以自行指定
  GO
  USE[master]
  GO
  ALTER DATABASE 要清理的数据库名称 SET RECOVERY FULL WITH NO_WAIT
  GO
  ALTER DATABASE 要清理的数据库名称 SET RECOVERY FULL  --还原为完全模式
  GO

	
	
-- 查看数据库表大小
Create Table #TableSpaceInfo --创建结果存储表 
(
  NameInfo NVarchar(50) , 
  RowsInfo int , 
  Reserved NVarchar(20) , 
  DataInfo NVarchar(20) , 
  Index_Size NVarchar(20) , 
  Unused NVarchar(20) 
)


Declare @TableName NVarchar(255) --表名称
Declare @CmdSql NVarchar(1000)

Declare Info_Cursor Cursor For
Select o.Name 
From dbo.sysobjects o 
Where objectProperty(o.ID, N'IsTable') = 1 and o.Name not like N'#%%' Order By o.Name

Open Info_Cursor

Fetch Next From Info_Cursor 
Into @TableName

While @@FETCH_STATUS = 0 
Begin
  If exists (Select * From dbo.sysobjects Where ID=object_ID(@tablename) and objectProperty(ID, N'IsUserTable') = 1) 
    Execute sp_executesql N'Insert Into #TableSpaceInfo Exec sp_Spaceused @TBName', N'@TBName NVarchar(255)', @TBName = @TableName

  Fetch Next From Info_Cursor 
  Into @TableName 
End

Close Info_Cursor 
Deallocate Info_cursor 
GO


--itlearner注：显示数据库信息 
sp_spaceused @UpdateUsage = 'TRUE'

--itlearner注：显示表信息 
Select * 
From #TableSpaceInfo 
Order By cast(left(lTrim(rTrim(Reserved)) , len(lTrim(rTrim(Reserved)))-2) As Int) Desc


Drop Table #TableSpaceInfo



